package net.sf.window.scope;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class WindowScopeTestServlet implements Servlet {

	@Override
	public void destroy() {

	}

	@Override
	public ServletConfig getServletConfig() {
		return null;
	}

	@Override
	public String getServletInfo() {
		return null;
	}

	@Override
	public void init(ServletConfig arg0) throws ServletException {

	}

	@Override
	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		HttpServletRequest req = (HttpServletRequest) request;
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(
														req.getSession().getServletContext());
		IdPrinter idPrint = (IdPrinter) wac.getBean("idPrinter");
		/*Enumeration<String> headerNames = req.getHeaderNames(); 
		while(headerNames.hasMoreElements())
		{
			System.out.println(headerNames.nextElement());
		}
		System.out.println(req.getHeader("x-requested-with"));*/
		response.getOutputStream().write(idPrint.printIdWithSession(req.getSession()).getBytes());
		response.getOutputStream().flush();
	}
}
